#ifndef __RESULTQUOTE_HPP__
#define __RESULTQUOTE_HPP__

#include <string>
#include <map>
#include <vector>

#include "DataTypes.hpp"
#include "FieldNameLookup.hpp"


/*
  A ResultQuote object contains an std::map of FieldValuePair's

  FieldValuePair
  --------------
  Data originally comes from XML in the format:  <FieldName>strDataValue</FieldName>  
  Each FieldValuePair connects a FieldName to a strDataValue.
  For convinence strFieldName and FieldNameType are also stored.
  
  ResultQuote
  -----------
  Contains a std:map of FieldValuePair, and a vector of FieldName's in the map.
  Given a FieldName, returns desired value(s) from the matching FieldValuePair.
*/


class FieldValuePair
{
public:
  FieldValuePair() : fieldName(FieldName::Unknown), fieldNameType(FieldNameType::Unknown) { }
  FieldValuePair(FieldName fieldName, std::string strFieldName, std::string strDataValue, FieldNameType fieldNameType = FieldNameType::Unknown);
public:
  FieldName     getFieldName()       { return this->fieldName; }
  std::string   getFieldNameString() { return this->strFieldName; }
  FieldNameType getFieldNameType()   { return this->fieldNameType; }
  std::string   getDataValue(TrimOptions trimOptions = TrimOptions::None);
  bool          convertToSQLDate(std::string strMM_DD_YYYYDate, std::string& strSQLDate);
private:
  FieldName     fieldName;      
  std::string   strFieldName;  
  std::string   strDataValue;
  FieldNameType fieldNameType;  
};


class ResultQuote
{
public: // TOR
  ResultQuote() { };
  ResultQuote(std::string quoteSymbol);
public: // Exec
  void addRawPair(FieldName fieldName, std::string strFieldName, std::string strDataValue, 
		  FieldNameType fieldNameType = FieldNameType::Unknown);
public: // Accessors
  std::string getSymbol() { return this->quoteSymbol; }
  VectorFieldName getAllFieldNames() { return this->vecFieldNamesInMap; }   
public: // FV accessors
  bool lookupFieldNameString(FieldName fieldName, std::string& strFieldName);
  bool lookupDataString(FieldName fieldName, std::string& strDataString, TrimOptions trimOptions = TrimOptions::None, bool bVerifyNumber = false);
  bool lookupFieldType(FieldName fieldName, FieldNameType& fieldNameType);
private:
  bool getFieldValuePair(FieldName fieldName, FieldValuePair& fieldValuePair);
  bool getFieldValuePair(FieldName fieldName, std::string& strFieldName, std::string& strDataValue, FieldNameType& fieldNameType, TrimOptions trimOptions = TrimOptions::None);   
private:
  std::string verifyNumber(std::string strNumber, FieldNameType fieldNameType);
private: // Internal vars
  std::string quoteSymbol;
public:
private:
  MapFieldNameToFieldValue mapFieldData;      // FieldName and FieldValuePair mappings
  VectorFieldName vecFieldNamesInMap;         
};


/*
 yahoo.finance.quotes format
 Query
    Result
       Quote symbol="YHOO"
          "Ask", "Avg Volume", "Bid"
       Quote symbol="GE"
          "Ask", "Avg Volume", "Bid"
       ...	  
 
 yahoo.finance.historical format
 Query
    Diagnostics
    Results
       Quote symbol="YHOO"
          date, open, high, low
       Quote symbol="GE"
          date, open, high, low
          
  YQLQuotes and YQLHistorical use TinyXML to locate Query / Diagnostics / Result, and then loop through
  each Quote. Each Quote object is placed in a ResultQuote.
  ResultQuote knows the symbol name, and contains a map of FieldName to FieldValuePairs.
  
*/



#endif